package com.jsrj.controller;

import com.alipay.api.AlipayApiException;
import com.jsrj.common.core.controller.BaseController;
import com.jsrj.common.core.domain.AjaxResult;
import com.jsrj.dto.UsersDto;
import com.jsrj.model.WXAuth;
import com.jsrj.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-09-07
 */
@RestController
@RequestMapping("/system/users")
public class UsersController extends BaseController
{
    @Autowired
    private IUsersService usersService;

    /**
     * 获取微信小程序登录状态
     * @param wxAuth
     * @return 微信用户信息以及token
     */
    @PostMapping("/login")
    public AjaxResult getToken(@RequestBody WXAuth wxAuth){
        UsersDto usersDto = usersService.getCode(wxAuth);
        return AjaxResult.success(usersDto);
    }

    /**
     * 获取支付宝小程序登录状态
     * @param authCode
     * @return 支付宝用户信息以及token
     */
    @PostMapping("/alipay-login")
    public AjaxResult getAlipayToken(@RequestBody String authCode) throws AlipayApiException {
        return usersService.getAlipayToken(authCode);
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/userinfo")
    public AjaxResult userInfo(String token,Boolean refresh){
        return usersService.userinfo(token,refresh);
    }


}
